//-----------------------------------------------------------------------------
// Copyright (c) 2011 David Waby
// Initially created on 02/11/2011
//-----------------------------------------------------------------------------

#include "Global.h"
#include "Renderer.h"
#include "Map.h"
#include "Character.h"
#include "Tile.h"
#include "TileAttribute.h"
#include <iostream>

//-----------------------------------------------------------------------------
Renderer::Renderer()
{
} 

//-----------------------------------------------------------------------------
Renderer::~Renderer()
{
} 

//-----------------------------------------------------------------------------
void Renderer::RenderMap(Map const * i_map, Character const * i_character)
{
	using namespace std;

	Point2 size = *i_map->GetSize();
	Point2 characterPosition = *i_character->GetPosition();

	system("CLS");
	Point2 currentTile;
	for (int y = size[Y]-1; y >= 0; --y)
	{
		currentTile[Y] = y;
		for (int x = 0; x < size[X]; ++x)
		{
			currentTile[X] = x;

			if (currentTile == characterPosition)
			{
				cout << "C";
			}
			else
			{
				Tile const * tile = i_map->GetTile(x, y);
				TileAttribute const * attribute = tile->GetAttribute();
				if (attribute)
				{				
					if (attribute->GetAttributeType() == Tile::TileAttributes::Portal)
					{
						cout << "P";
						continue;
					}
					else if (attribute->GetAttributeType() == Tile::TileAttributes::Chest)
					{
						cout << "I";
						continue;
					}
				}
				else if (tile->HasAttribute(Tile::TileAttributes::Walkable))
					cout << ".";
				else
					cout << "#";
			}
		}
		cout << endl;
	}
}